import 'package:flutter/material.dart';
import 'package:mandoby/core/utils/app_colors.dart';
import 'package:mandoby/core/widgets/custom_scaffold_widget.dart';
import 'package:mandoby/features/nationally/presentation/pages/nationally_screen.dart';
import 'package:mandoby/features/splash/splash_screen.dart';
import 'package:nb_utils/nb_utils.dart';
import '../../../core/app_export.dart';

enum Style { bgFill }

// ignore: must_be_immutable
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  const CustomAppBar(
      {Key? key,
      this.height,
      this.styleType,
      this.leadingWidth,
      this.leading,
      this.title,
      this.centerTitle,
      this.actions})
      : super(
          key: key,
        );

  final double? height;

  final Style? styleType;

  final double? leadingWidth;

  final Widget? leading;

  final Widget? title;

  final bool? centerTitle;

  final List<Widget>? actions;

  @override
  Widget build(BuildContext context) {
    return AppBar(
      elevation: 0.5,

      toolbarHeight: height ?? 81.h,
      backgroundColor: Colors.white,
      flexibleSpace: _getStyle(context),
      leadingWidth: leadingWidth ?? 40,

      surfaceTintColor: Colors.transparent,
      leading: const SizedBox.shrink(),

      // leading: Container(
      //   height: 40,
      //   decoration: BoxDecoration(
      //     color: AppColors.primary,
      //     borderRadius: BorderRadius.circular(4)
      //   ),
      //   child: leading ??
      //       IconButton(
      //           onPressed: () => finish(context), icon: Icon(Icons.arrow_back,color: Colors.white,)),
      // ),
      // title: title ?? CustomImageView(imagePath: AppAssets.imgRectangle22,width: 200.w,),
      // titleSpacing: 0,
      // centerTitle: centerTitle ?? true,
      // actions: actions??[IconButton(onPressed: () =>finish(context) , icon: Icon(Icons.menu))],
    );
  }

  @override
  Size get preferredSize => Size(
        SizeUtils.width,
        height ?? 81.h,
      );

  _getStyle(context) {
    return Container(
      height: 120.h,
      width: double.maxFinite,
      alignment: Alignment.bottomCenter,
      decoration: const BoxDecoration(
        color: Colors.white38,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 4.h),
            decoration: BoxDecoration(
                color: AppColors.whiteA700,
                borderRadius: BorderRadius.circular(7)),
            child: const Icon(
              Icons.menu,
              color: Colors.black,
              size: 24,
            ),
          ).onTap(() {
            Scaffold.of(context).openDrawer();
          }),
          CustomImageView(
            imagePath: AppAssets.imgRectangle22,
            width: 200.w,
          ),
          Container(
            padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 4.h),
            decoration: BoxDecoration(
                color: AppColors.primary,
                borderRadius: BorderRadius.circular(7)),
            child: const Icon(
              Icons.arrow_forward,
              color: Colors.white,
              size: 24,
            ),
          ).onTap(() {
            if (Navigator.canPop(context)) {
              Navigator.pop(context);
            } else {
              NationallyScreen().launch(context, isNewTask: true);
            }
          }),
        ],
      ).paddingSymmetric(horizontal: 10.w),
    );
  }
}
